cd "C:\Users\hanollee\Dropbox\BIHS\"

use "Section3_5_z\Data\tmp_2018a_male.dta", clear
merge 1:m year a01 using "Section3_5_z\Data\tmp_2018b1_male.dta"
rename _merge merge
label var merge "Section3_5_z\Data\merge results A+B"
merge m:m year a01 using "Section3_5_z\Data\tmp_2018_hsize"
drop _merge
merge 1:1 a01 mid using "Section3_5_z\Data\tmp_2018w3_female"
drop _merge
merge 1:1 a01 mid using "Section3_5_z\Data\tmp_2018w4_female"
drop _merge
merge 1:1 a01 mid using "Section3_5_z\Data\tmp_2018z_female"
drop _merge
merge m:1 a01 using "Section3_5_z\Data\158_BIHS sampling weights_r3"
drop _merge
merge m:1 a01 mid using "Section3_5_z\Data\tmp_2018xxc"
drop _merge
merge m:1 a01 mid using "Section3_5_z\Data\tmp_2018xxab"
drop _merge
merge m:1 a01 using "Section3_5_z\Data\tmp_2015a_region"
drop _merge
merg m:1 a01 mid using "Section3_5_z\Data\tmp_2018we7_male"
drop _merge
merg m:1 a01 mid using "Section3_5_z\Data\tmp_2018we7_female"
drop _merge

/*
use "Section3_5_z\Data\tmp_2018a_male.dta", clear
merge 1:m year a01 using "Section3_5_z\Data\tmp_2018b1_male.dta"
rename _merge merge
label var merge "Section3_5_z\Data\merge results A+B"
merge m:m year a01 using "Section3_5_z\Data\tmp_2018_hsize"
drop _merge
merge 1:1 a01 mid using "tmp_2018c_male"
drop _merge
merge m:1 a01 using "tmp_2018q_male"
drop _merge
merge m:1 a01 using "tmp_2018t1_male"
drop _merge
merge m:1 a01 using "tmp_2018t2_male"
drop _merge
merge m:1 a01 using "tmp_2018u_male"
drop _merge
merge m:1 a01 using "tmp_2018v1_male"
drop _merge
merge m:1 a01 using "tmp_2018v2_male"
drop _merge
merge m:1 a01 using "tmp_2018v3_male"
drop _merge
merge m:1 a01 using "tmp_2018v4_male"
drop _merge
merge 1:1 a01 mid using "tmp_2018w3_female"
drop _merge
merge 1:1 a01 mid using "tmp_2018w4_female"
drop _merge
merge 1:1 a01 mid using "tmp_2018z_female"
drop _merge
merge m:1 a01 mid using "tmp_2018xxc"
drop _merge
merge m:1 a01 mid using "tmp_2018xxab"
drop _merge
merge m:1 a01 using "158_BIHS sampling weights_r3"
drop _merge
merge m:1 a01 using "tmp_2015a_region"
drop _merge
merg m:1 a01 mid using "tmp_2018we7_male"
drop _merge
merg m:1 a01 mid using "tmp_2018we7_female"
drop _merge
*/
g motheredu =mothereduM
replace motheredu = mothereduF if motheredu==.

g fatheredu =fathereduM
replace fatheredu = fathereduF if fatheredu==.

g whereyouborn =whereyoubornM
replace whereyouborn = whereyoubornF if whereyouborn==.

keep if cmage!=.

g myear = 2018-age+cmage

g birthyear = 2018-age

g female = (sex == 2)

*keep if sex==2

keep a01 cmage popweight myear age birthyear div village female motheredu fatheredu whereyouborn div
keep if age>=9 & age<=31
g id=_n

save "Section3_5_z\Data\tmp_2018_survival_xx.dta", replace

keep a01 id 

expand 38

g cmage = 1
bysort id: replace cmage = sum(cmage)
replace cmage = cmage+8

merge m:1 a01 id cmage using "Section3_5_z\Data\tmp_2018_survival_xx.dta"
drop _merge


sort id cmage
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.
replace age = age[_n+1]-1 if id == id[_n+1] & age==. & age[_n+1]!=.

replace age = age[_n-1]+1 if id == id[_n-1] & age==. & age[_n-1]!=.

g married_survival = (myear!=.)
replace married_survival = . if id == id[_n-1] & married_survival==0 & married_survival[_n-1]==1
replace married_survival = . if id == id[_n-1] & married_survival==0 & married_survival[_n-1]==.

replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.
replace birthyear = birthyear[_n+1] if id == id[_n+1] & birthyear==. & birthyear[_n+1]!=.

replace birthyear = birthyear[_n-1] if id == id[_n-1] & birthyear==. & birthyear[_n-1]!=.


replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.

replace div = div[_n-1] if id == id[_n-1] & div==. & div[_n-1]!=.

replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.
replace motheredu = motheredu[_n+1] if id == id[_n+1] & motheredu==. & motheredu[_n+1]!=.

replace motheredu = motheredu[_n-1] if id == id[_n-1] & motheredu==. & motheredu[_n-1]!=.


replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.
replace fatheredu = fatheredu[_n+1] if id == id[_n+1] & fatheredu==. & fatheredu[_n+1]!=.

replace fatheredu = fatheredu[_n-1] if id == id[_n-1] & fatheredu==. & fatheredu[_n-1]!=.


replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.
replace whereyouborn = whereyouborn[_n+1] if id == id[_n+1] & whereyouborn==. & whereyouborn[_n+1]!=.

replace whereyouborn = whereyouborn[_n-1] if id == id[_n-1] & whereyouborn==. & whereyouborn[_n-1]!=.

replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.
replace female = female[_n+1] if id == id[_n+1] & female==. & female[_n+1]!=.

replace female = female[_n-1] if id == id[_n-1] & female==. & female[_n-1]!=.


replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.
replace popweight = popweight[_n+1] if id == id[_n+1] & popweight==. & popweight[_n+1]!=.

replace popweight = popweight[_n-1] if id == id[_n-1] & popweight==. & popweight[_n-1]!=.

replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.
replace div = div[_n+1] if id == id[_n+1] & div==. & div[_n+1]!=.

replace div = div[_n-1] if id == id[_n-1] & div==. & div[_n-1]!=.

replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.
replace village = village[_n+1] if id == id[_n+1] & village==. & village[_n+1]!=.

replace village = village[_n-1] if id == id[_n-1] & village==. & village[_n-1]!=.

g year = myear

replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.
replace year = year[_n+1]-1 if id == id[_n+1] & year==. & year[_n+1]!=.

replace year = year[_n-1]+1 if id == id[_n-1] & year==. & year[_n-1]!=.


merge m:m a01 using  "Section3_5_z\Data\precip_z_clean.dta"
drop _merge

merge m:m a01 using  "Section3_5_z\Data\temp_clean.dta"
drop _merge


g precip_z = .
forval x = 1951(1)2015{
	replace precip_z = precip_z`x' if year==`x'
}

g extremeheat = .
forval x = 1961(1)2015{
	replace extremeheat = extremeheat`x' if year==`x'
}
drop precip_z1951 -  extremeheat2015
keep if cmage<18


egen gridcell = group(latitude longitude)

save "Section3_5_z\Data\survival_CBS4.dta", replace





